package com.lzyboyl.big.data.handle.config;

import com.lzyboyl.big.data.handle.task.BigDataHandleTask;
import com.lzyboyl.big.data.handle.util.RedisCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author linzef
 * @since 2021-08-02
 * 类描述： 配置类
 */
@Configuration
public class BigDataHandleConfig {


    private Logger logger = LoggerFactory.getLogger(BigDataHandleConfig.class);

    /**
     * redis工具类
     */
    @Resource
    private RedisCache redisCache;

    @PostConstruct
    public void init() {
        logger.info("------------------------启动超大数据监听线程------------------------");
        ExecutorService es = new ThreadPoolExecutor(5, 5, 0, TimeUnit.SECONDS, new SynchronousQueue<>(),
                r -> {
                    Thread t = new Thread(r);
                    t.setDaemon(true);
                    t.setName("big-data" + r);
                    return t;
                }, (runnable, executor) -> {
        });
        BigDataHandleTask bigDataHandleTask = new BigDataHandleTask(redisCache);
        es.execute(bigDataHandleTask);
        logger.info("------------------------完成超大数据监听启动------------------------");
    }

}
